<template>
    <div>
      <h1>科室显示</h1>
      <a href="/addks">科室信息录入</a>
      <br>
      
 <a href="/showys">医生信息显示</a>
<br>

 <a href="/">病房信息显示</a>
<br>
<a href="https://localhost:7293/api/HouseKS/DaochuHouse">科室信息导出</a>
<br>
      科室名称:
      <input type="text" placeholder="科室名称" v-model="page.ksname">
      创建日期:
      <input type="date" v-model="page.d1">
      -
      <input type="date" v-model="page.d2">
      <input type="button" value="查询" @click="chax">
      <input type="button" value="清空" @click="qk">
      <table class="table">
       <thead>
             <tr>
                <td>科室编号</td>
                <td>科室名称</td>
                <td>科室人数</td>
                <td>科室描述</td>
                <td>创建日期</td> 
                <td>逻辑删除</td> 
                <td>修改</td> 
             </tr>
       </thead>
       <tbody>
            <tr v-for="e in data">
                <td>{{ e.id }}</td>
                <td>{{ e.ksName }}</td>
                <td>{{ e.kScount }}</td>
                <td>{{ e.ksms }}</td>
                <td>{{ moment(e.ksDate).format("YYYY-MM-DD") }}</td> 
                <td>
                    <input type="button" value="逻辑删除" @click="deleteks(e.id)">
                </td>
                  <td>
                    <input type="button" value="修改" @click="updateks(e.id)">
                </td>
             </tr>
       </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'
import moment  from 'moment';
const router=useRouter();

onMounted(()=>{
    show();
})
//修改
const updateks=(val:any)=>{
     if(!confirm("确认修改吗"))
{
    return;
}
   router.push({path:"/upks",query:{id:val}})
}

//删除
const deleteks=(val:any)=>{
    if(!confirm("确认删除吗"))
{
    return;
}
   axios.delete("/api/HouseKS/DeleteKs",{params:{id:val}}).then(res=>{
        if(res.data>0)
        {
            alert("逻辑删除成功")
            show();
        }
        else{
            alert("逻辑删除失败");
            return;
        }
   })
}

//查询
const chax=()=>{
    show();
}
//清空
const qk=()=>{
    page.value.d1="";
    page.value.d2="";
    page.value.ksname="";
}

const data =ref([{
    "id": 1,
    "ksName": "骨科",
    "kScount": 5,
    "ksms": "string",
    "ksDate": "2025-05-19T01:38:39.114",
    "isDelete": false
  }])

const page=ref({
    ksname:"",
    d1:"",
    d2:"",
})

  const show=()=>{
    axios.get("/api/HouseKS/ShowHouseKS",{params:page.value}).then(res=>{
        data.value=res.data
    })
  }

</script>

<style scoped>

</style>